package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.article.service.ApAuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController {

    @Autowired
    ApAuthorService apAuthorService;

    @GetMapping("/findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery()
                .eq(ApAuthor::getUserId, id));
    }

    @GetMapping("/findApAuthorById/{id}")
    public ApAuthor findApAuthorById(@PathVariable("id") Integer id) {
        return apAuthorService.getById(id);
    }


    @PostMapping("/save")
    public boolean save(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.save(apAuthor);
    }

}
